﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace TeamDeploy.Activities
{
    class ThreadPoolHelper
    {
        public static bool QueueUserWorkItem(Action callback)
        {

            return ThreadPool.QueueUserWorkItem((o) => callback());

        }



        public static bool QueueUserWorkItem<T>(T arg, Action<T> callback)
        {

            return ThreadPool.QueueUserWorkItem(s => callback((T)s), arg);

        }



        public static bool QueueUserWorkItem<T1, T2>(T1 arg1, T2 arg2, Action<T1, T2> callback)
        {

            return ThreadPoolHelper.QueueUserWorkItem(

                new { Arg1 = arg1, Arg2 = arg2 },

                (args) =>
                {

                    callback(args.Arg1, args.Arg2);

                });

        }



        public static bool QueueUserWorkItem<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3, Action<T1, T2, T3> callback)
        {

            return ThreadPoolHelper.QueueUserWorkItem(

                new { Arg1 = arg1, Arg2 = arg2, Arg3 = arg3 },

                (args) =>
                {

                    callback(args.Arg1, args.Arg2, args.Arg3);

                });

        }



        public static bool QueueUserWorkItem<T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action<T1, T2, T3, T4> callback)
        {

            return ThreadPoolHelper.QueueUserWorkItem(

                new { Arg1 = arg1, Arg2 = arg2, Arg3 = arg3, Arg4 = arg4 },

                (args) =>
                {

                    callback(args.Arg1, args.Arg2, args.Arg3, args.Arg4);

                });

        }

    }
}
